package Controls;

import Core.Control;
import Core.GUICanvas;
import Core.Key;
import Core.Tween;
import Core.TweenInterface;
import javax.microedition.lcdui.Graphics;

public class TweenTestControl extends Control implements TweenInterface
{
    int linex = 0;
    Tween tw;

    public TweenTestControl(int w, int h)
    {
        super(w, h);
        lockOn = true;
    }

    public void tweenTick(Tween t)
    {
        t.block();

        System.out.println("Repaint linex = "+linex);

        linex = (int) Math.floor(t.getValue());

        GUICanvas.inst.repaint();
        GUICanvas.inst.serviceRepaints();

        t.release();
    }

    public void draw(Graphics g, int x, int y)
    {
        super.draw(g, x, y);
        g.drawRect(x, y, getW(), getH());
        g.drawLine(x+linex, y, x+linex, y+getH());
    }

    public void processKey(int key, int state)
    {
        super.processKey(key, state);

        if(state != Key.PRESSED) return;

        if(key == GUICanvas.KEY_NUM1)
        {
            tw = new Tween(this, 400, Tween.LINEAR, 0, getW());
            tw.enable();
            System.out.println("Tween enabled");
        }
    }

    
}
